package com.itheima.mapper;

import com.itheima.pojo.MemberCount;
import com.itheima.pojo.SetmealCount;
import org.apache.ibatis.annotations.Mapper;
import org.apache.ibatis.annotations.Select;

import java.util.List;

@Mapper
public interface StatisticMapper {

    //获取会员数量统计数据
    @Select("select regTime months ,count(*) memberCount from t_member group by regTime")
    List<MemberCount> getMemberReport();

    //获取预约套餐占比统计数据
    @Select("select s.name AS name ,count(o.setmeal_id) AS value " +
            "from t_setmeal s left join t_order o on s.id = o.setmeal_id" +
            " group by name")
    List<SetmealCount> getSetmealReport();



    // 会员数据统计
    @Select("select count(*) from t_member where regTime = current_date")
    int getTodayNewMember(); // 获取今日新增会员数
    @Select("select count(*) FROM t_member where yearweek(regTime, 1) = yearweek(current_date, 1)")
    int getThisWeekNewMember(); // 获取本周新增会员数
    @Select("select count(*) from t_member where month(regTime) = month(current_date) and year(regTime) = year(current_date)")
    int getThisMonthNewMember(); // 获取本月新增会员数
    @Select("select count(*) from t_member")
    int getTotalMember(); // 获取总会员数

    //预约到诊数据统计
    @Select("select count(*) from t_order where orderDate = current_date")
    int getTodayOrderNumber(); // 获取今日预约数
    @Select("select count(*) from t_order where yearweek(orderDate, 1) = yearweek(current_date,1)")
    int getThisWeekOrderNumber(); // 获取本周预约数
    @Select("select count(*) from t_order where month(orderDate) = month(current_date) and year(orderDate) = year(current_date)")
    int getThisMonthOrderNumber(); // 获取本月预约数
    @Select("select count(*) from t_order where orderStatus = '已到诊' and orderDate = current_date")
    int getTodayVisitsNumber(); // 获取今日到诊数
    @Select("select count(*) from t_order where orderStatus = '已到诊' and yearweek(orderDate,1) = yearweek(current_date,1)")
    int getThisWeekVisitsNumber(); // 获取本周到诊数
    @Select("select count(*) from t_order where orderStatus = '已到诊' and month(orderDate) = month(current_date) and year(orderDate) = year(current_date)")
    int getThisMonthVisitsNumber(); // 获取本月到诊数


    // 热门套餐数据统计
    @Select("select count(*) from t_setmeal")
    int getTotalSetmealCounts(); // 获取总套餐数量
}
